from queue import Queue

class Staircase(object):
    """defines a Staircase"""
    def __init__(self, staircasecapacity):
        self.capacity = staircasecapacity
        self.people = []

    def queueperson(self, person):
        if not (len(self.people) + 1 > self.capacity):
            self.people.append(person)
            return True
        return False

    def dequeueperson(self, person):
        try:
            self.people.remove(person)
        except ValueError:
            print(str(person.id) + " not found in queue")

    # adds people to the queue
    def addperson(self, person):
        if self.queueperson(person):
            person.state = 1
            print("{0} entered (staircase)".format(person.id))
        else:
            print("{0} waiting (staircase)".format(person.id))

    # handles a timestep for all people queued
    def handle(self):
        for person in self.people:
            if person.state == 1:
                self.dequeueperson(person)
                person.state = 5
                print("{0} left (staircase)".format(person.id))
